package com.eqdd.yiqidian.ui.select;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.LayoutRes;

import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.bean.rebuild.ISelectBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lv on 17-8-28.
 */

public class MultiSelectBuilder {
//    private static MultiSelectBuilder sInstance;
    int layoutId;
    int maxSelectNum = -1;
    int minSelectNum = -1;
    int mode;
    List<ISelectBean> allDatas = new ArrayList<>();
    List<ISelectBean> selectDatas = new ArrayList<>();
    List<ISelectBean> disableDatas = new ArrayList<>();
    String compareField;
    private static OnInject onInject;

//    public static MultiSelectBuilder getInstance() {
//        if(sInstance == null) {
//            Class var0 = PictureConfig.class;
//            synchronized(PictureConfig.class) {
//                if(sInstance == null) {
//                    sInstance = new MultiSelectBuilder();
//                }
//            }
//        }
//
//        return sInstance;
//    }

    public static OnInject getOnInject() {
        return onInject;
    }

    public MultiSelectBuilder setMode(int mode) {
        this.mode = mode;
        return this;
    }

    public MultiSelectBuilder setMaxSelectNum(int maxSelectNum) {
        this.maxSelectNum = maxSelectNum;
        return this;
    }

    public MultiSelectBuilder setMinSelectNum(int minSelectNum) {
        this.minSelectNum = minSelectNum;
        return this;
    }

    public MultiSelectBuilder setAllDatas(List<? extends ISelectBean> allDatas) {
        ArrayList<ISelectBean> temp = new ArrayList<>();
        temp.addAll(allDatas);
        this.allDatas = temp;
        return this;
    }

    public MultiSelectBuilder setSelectDatas(List<? extends ISelectBean> selectDatas) {
        ArrayList<ISelectBean> temp = new ArrayList<>();
        temp.addAll(selectDatas==null?new ArrayList<>():selectDatas);
        this.selectDatas = temp;
        return this;
    }

    public MultiSelectBuilder setDisableDatas(List<? extends ISelectBean> disableDatas) {
        ArrayList<ISelectBean> temp = new ArrayList<>();
        temp.addAll(disableDatas);
        this.disableDatas = temp;
        return this;
    }

    public MultiSelectBuilder setCompareField(String compareField) {
        this.compareField = compareField;
        return this;
    }

    public MultiSelectBuilder(@LayoutRes int layoutId) {
        this.layoutId = layoutId;
    }


    public static int SINGLE_MODE = 0;
    public static int MULTI_MODE = 1;

    public void build(BaseActivity activity, int requestCode, OnInject onInject) {
        Bundle bundle = new Bundle();
        bundle.putInt("layoutId", layoutId);
        bundle.putInt("mode", mode);
        bundle.putString("compareField", compareField);
        bundle.putParcelableArrayList("allDatas", (ArrayList<ISelectBean>) allDatas);
        bundle.putParcelableArrayList("selectDatas", (ArrayList<ISelectBean>) selectDatas);
        bundle.putParcelableArrayList("disableDatas", (ArrayList<ISelectBean>) disableDatas);
        bundle.putInt("maxSelectNum", maxSelectNum);
        bundle.putInt("minSelectNum", minSelectNum);
        activity.startActivityForResult(MultiSelectActivity.class, bundle, requestCode);
        MultiSelectBuilder.onInject = onInject;
    }

    public interface OnInject {
        void inject(ISelectBean data, IViewInjector inject);
    }

}
